<div class="container" style="width: 100%;">
	<form id="inputForm" class="form-horizontal" style="overflow: auto;">
		<input name="id" type="hidden" id="id"/>
		<input name="hashKey" type="hidden" id="hashKey"/>
		<input name="formNo" type="hidden" id="formNo"/>
	  	<div class="col-md-6 half-line col-sm-12 adapt">
	  		<label>归属NFT合约</label>
	  		<fieldset class="set">
	  			<div name="g01.id" component-type="grid" class="tag-div required" tableName="tspace_nft_contract" searchKey="name" fieldKeys="s01,s14" fieldLabels="名称,合约简述" searchLabel="名称" javaField="g01.id|s01"></div>
	  		</fieldset>
	  	</div>
	  	<div class="col-md-12 all-line col-sm-12 adapt">
	  		<label>名称</label>
	  		<fieldset class="set">
				<input name="s01" component-type="input" type="text"    class="form-control  required"/>
	  		</fieldset>
	  	</div>
	  	<div class="col-md-12 all-line col-sm-12 adapt">
	  		<label>图标</label>
	  		<fieldset class="set">
				<input name="s02" component-type="input" type="text"    class="form-control  "/>
	  		</fieldset>
	  	</div>
	  	<div class="col-md-12 all-line col-sm-12 adapt">
	  		<label>主图</label>
	  		<fieldset class="set">
				<input name="s03" component-type="input" type="text"    class="form-control  "/>
	  		</fieldset>
	  	</div>
	  	<div class="col-md-12 all-line col-sm-12 adapt">
	  		<label>链接</label>
	  		<fieldset class="set">
				<input name="s04" component-type="input" type="text"    class="form-control  "/>
	  		</fieldset>
	  	</div>
	  	<div class="col-md-12 all-line col-sm-12 adapt">
	  		<label>描述</label>
	  		<fieldset class="set">
				<textarea name="s05" component-type="textarea" rows="3"    class="form-control  "></textarea>
	  		</fieldset>
	  	</div>
	  	<div class="col-md-6 half-line col-sm-12 adapt">
	  		<label>铸造NFT（标记）</label>
	  		<fieldset class="set">
				<input name="s10" component-type="input" type="text"    class="form-control  required"/>
	  		</fieldset>
	  	</div>
	  	<div class="col-md-6 half-line col-sm-12 adapt">
	  		<label>是否认证</label>
	  		<fieldset class="set">
	  			<select name="s11" component-type="select" component-id="yes_no" class="form-control required">
					<option></option>
				</select>
	  		</fieldset>
	  	</div>
	  	<div class="col-md-6 half-line col-sm-12 adapt">
	  		<label>trending排序</label>
	  		<fieldset class="set">
				<input name="s09" component-type="input" type="text"    class="form-control  "/>
	  		</fieldset>
	  	</div>
	  	<div class="col-md-6 half-line col-sm-12 adapt">
	  		<label>设置为trending</label>
	  		<fieldset class="set">
	  			<select name="s08" component-type="select" component-id="yes_no" class="form-control ">
					<option></option>
				</select>
	  		</fieldset>
	  	</div>
	  	<div class="col-md-6 half-line col-sm-12 adapt">
	  		<label>拥有者</label>
	  		<fieldset class="set">
				<input name="s06" component-type="input" type="text"    class="form-control  "/>
	  		</fieldset>
	  	</div>
	</form>
	<div id="body-div">
		<div class="layui-tab layui-tab-brief">
			<div id="toolbarChild"><button id="addBtn" class="btn btn-sm btn-success"><i class="glyphicon "></i> 添加</button></div>
			<ul class="layui-tab-title">
				<li class="layui-this" data-url="tspace_collections_category">作品集所属分类</li>
				<li  data-url="tspace_collections_payment_tokens">作品集代币</li>
			</ul>
			<div class="layui-tab-content">
				<div class="layui-tab-item layui-show">
					<table id="table-list-tspace_collections_category"></table>
				</div>
				<div class="layui-tab-item">
					<table id="table-list-tspace_collections_payment_tokens"></table>
				</div>
			</div>
		</div>
	</div>
</div>

<script>
	//表单页自执行方法
	window.formFuction = function(res,layero){
        var getTime = "-" + new Date().getTime();
		//这段必须写，防止id重复
        $(layero).find("#body-div").attr("id", "body-div" + getTime);

		var bootstrapTableUtilArr = [];
		pushArr();
		function pushArr(){
			var bootstrapTableUtil_tspace_collections_category = new BootstrapTableUtil("-tspace_collections_category",false,getTime);
			bootstrapTableUtil_tspace_collections_category.init({
				url: layui.admin.basePath + '/dynamic/zform/dataChildren?formNo=tspace_collections_category&path=path&traceFlag=&parentId=' + $(layero).find("#id").val(),
				method: 'post',
				columns: [
					{
						checkbox: false
					}
					,{
						field: 'g01.name',
						title: '作品集',
						sortable: true
						
						,formatter:function(value, row , index){
							if(value == null){
								return "<a href='javascript:;' class='view'>-</a>";
							}else{
								return "<a href='javascript:;' class='view'>"+value+"</a>";
							}
						},
						events: {
							'click .view': function (e, value, row, index) {
								viewForm({
									id: row.id
								})
							}
						},
					}
					,{
						field: 'g02.name',
						title: '所属分类',
						sortable: true
						
					}
					,{
					title: layui.admin.lang() ? 'Operation' : '操作',
                	width: '45px',
					"class": 'center must',
					events: {
						'click .edit': function (e, value, row, index) {
							addOrEdit({
								id: row.id,
								parent:{
									id: $(layero).find("#id").val()
								}
							})
						},
						'click .del': function (e, value, row, index) {
							delFuc(row);
						},
						'click .view': function (e, value, row, index) {
							viewForm({id: row.id})
						},
					},
					formatter: function(value, row, index) {
						return  '<div class="show-btn-group">'+
							'<i class="fa fa-cog" aria-hidden="true"></i>'+
							'<div class="hide-btn-group" style="width: 240px;">'+
								'<a class="btn view" dealname="查看">查看</a>'+
								'<a class="btn edit" dealname="编辑">编辑</a>'+
								'<a class="btn del" dealname="删除">删除</a>'+
							'</div>'+
						'</div>';
					}
				}],
			});
			bootstrapTableUtilArr.push(bootstrapTableUtil_tspace_collections_category);
			/*
			if($(layero).find("#id").val()!==''){
				var str = '<button id="tspace_collections_categoryImport" class="btn btn-sm btn-success"> 导入</button>';
				$("#body-div"+getTime).find("#toolbarChild").append(str);
				myHelper.initWebUploader('tspace_collections_categoryImport', false, '/system/sysFile/fileUploadBatchProgress',false,true,$(layero).find("#id").val(),'-'+$(layero).find("#body-div"+getTime).find(".layui-this").attr("data-url"));
			}
			*/
			var bootstrapTableUtil_tspace_collections_payment_tokens = new BootstrapTableUtil("-tspace_collections_payment_tokens",false,getTime);
			bootstrapTableUtil_tspace_collections_payment_tokens.init({
				url: layui.admin.basePath + '/dynamic/zform/dataChildren?formNo=tspace_collections_payment_tokens&path=path&traceFlag=&parentId=' + $(layero).find("#id").val(),
				method: 'post',
				columns: [
					{
						checkbox: false
					}
					,{
						field: 'g02.name',
						title: '作品集',
						sortable: true
						
						,formatter:function(value, row , index){
							if(value == null){
								return "<a href='javascript:;' class='view'>-</a>";
							}else{
								return "<a href='javascript:;' class='view'>"+value+"</a>";
							}
						},
						events: {
							'click .view': function (e, value, row, index) {
								viewForm({
									id: row.id
								})
							}
						},
					}
					,{
						field: 'g01.name',
						title: '选择代币',
						sortable: true
						
					}
					,{
					title: layui.admin.lang() ? 'Operation' : '操作',
                	width: '45px',
					"class": 'center must',
					events: {
						'click .edit': function (e, value, row, index) {
							addOrEdit({
								id: row.id,
								parent:{
									id: $(layero).find("#id").val()
								}
							})
						},
						'click .del': function (e, value, row, index) {
							delFuc(row);
						},
						'click .view': function (e, value, row, index) {
							viewForm({id: row.id})
						},
					},
					formatter: function(value, row, index) {
						return  '<div class="show-btn-group">'+
							'<i class="fa fa-cog" aria-hidden="true"></i>'+
							'<div class="hide-btn-group" style="width: 240px;">'+
								'<a class="btn view" dealname="查看">查看</a>'+
								'<a class="btn edit" dealname="编辑">编辑</a>'+
								'<a class="btn del" dealname="删除">删除</a>'+
							'</div>'+
						'</div>';
					}
				}],
			});
			bootstrapTableUtilArr.push(bootstrapTableUtil_tspace_collections_payment_tokens);
			/*
			if($(layero).find("#id").val()!==''){
				var str = '<button id="tspace_collections_payment_tokensImport" class="btn btn-sm btn-success"> 导入</button>';
				$("#body-div"+getTime).find("#toolbarChild").append(str);
				myHelper.initWebUploader('tspace_collections_payment_tokensImport', false, '/system/sysFile/fileUploadBatchProgress',false,true,$(layero).find("#id").val(),'-'+$(layero).find("#body-div"+getTime).find(".layui-this").attr("data-url"));
			}
			*/
		}

		$(layero).find("#addBtn").on("click",function(){
			if(!$(layero).find("#id").val()){
				var validateForm = $(layero).find("#inputForm").validate({});
	        	if(validateForm.form()){
					var data = myHelper.composeData($(layero).find("#inputForm"));
					if (data.tempLoginName != undefined && data.tempLoginName == "") {
						data.tempLoginName = [];
					}
					LayerUtil.ajax({
						url : layui.admin.basePath + '/dynamic/zform/beforeSave',
						type : 'post',
						data : JSON.stringify(data),
						shade: true,
						success : function(res) {
							$(layero).find("#id").val(res.insertedId);
							$.each(bootstrapTableUtilArr, function(idx,obj) {
								obj.destroy();
							});
							bootstrapTableUtilArr = [];
							pushArr();
							addOrEdit({
								parent:{
							 		id: $(layero).find("#id").val()
								}
						   	});
						}
					});
	        	}
			}else{
				addOrEdit({
					parent:{
				 		id: $(layero).find("#id").val()
					}
			   	});
			}
		})

		function addOrEdit(initData) {
			var subTableName = $(layero).find("#body-div"+getTime).find(".layui-this").attr("data-url");
			var subTableComments = $(layero).find("#body-div"+getTime).find(".layui-this").text();
			var id = initData ? initData.id : '';
			LayerUtil.openDialog({
				title : layui.admin.lang() ? 'New ' + subTableComments : '添加' + subTableComments,
				formLay : subTableName,
				initData : initData,
				setDataWidthAjax : true,
				actionDataName : 'data',
				url : 'admin/' + subTableName + '/form',
				actionUrl : layui.admin.basePath + '/dynamic/zform/getZform?formNo=' + subTableName + '&id=' + id,
	            btn : ['保存', '取消'],
	            btn_EN : ['Save', 'Cancel'],
	            func1 : function(index,layero) {
					var data = myHelper.composeData($(layero).find("#inputForm"));
	            	LayerUtil.ajax({
                		url : layui.admin.basePath + '/dynamic/zform/save',
                		type : 'post',
                		data : JSON.stringify(data),
                		success : function(res) {
                			LayerUtil.success(res[LayerUtil.getMsgLang()]);
                			$.each(bootstrapTableUtilArr, function(idx,obj) {
								obj.refresh();
							});
                			layui.layer.close(index)
                		}
                	});
	            }
			})
		}

		function viewForm(initData) {
			var subTableName = $(layero).find("#body-div"+getTime).find(".layui-this").attr("data-url");
			var subTableComments = $(layero).find("#body-div"+getTime).find(".layui-this").text();
			LayerUtil.openDialogView({
				title : layui.admin.lang() ? 'View ' + subTableComments : '查看' + subTableComments,
				formLay : subTableName,
				initData : initData,
				url : 'admin/' + subTableName + '/form',
				actionUrl : layui.admin.basePath + '/dynamic/zform/getZform?formNo=' + subTableName + '&id=' + initData.id,
				actionDataName : 'data',
				setIdAndDoByAction : true,
			})
		}

		function delFuc(row){
    		LayerUtil.confirm(layui.admin.lang() ? 'Are you sure you want to delete?':'确认要删除吗？', function() {
    			var subTableName = $(layero).find("#body-div"+getTime).find(".layui-this").attr("data-url");
				LayerUtil.ajax({
					url: layui.admin.basePath + '/dynamic/zform/delete?formNo=' + subTableName + '&ids=' + row.id,
					type:'post',
	        		shade:true,
					success: function(res){
	        			LayerUtil.success(res[LayerUtil.getMsgLang()]);
	        			$.each(bootstrapTableUtilArr, function(idx,obj) {
            				obj.refresh();
            			});
	        		}
				});
			});
    	}

	}
</script>
